home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 724 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. From: elesueur@ens-lyon.fr (Emmanuel Lesueur)
  2. Message-ID: <4i9rbn$fgj@cri.ens-lyon.fr>
  3. X-Original-Date: 14 Mar 1996 19:17:11 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 15 Mar 96 00:48:43 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Static member functions and overloading resolution
  9. Organization: Ecole Normale Superieure de Lyon, France
  10. Reply-To: elesueur@ens-lyon.fr
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMUi+jOEDnX0m9pzZAQHVzwF+LJwTYyyD24StyXA849CY/xjJ7tulbc3d
  13.     eZYkmH1OWVwf011ZD8OHjXRQsukQG+pq
  14.     =uWU+
  15.  
  16. Consider the following situation:
  17.  
  18.     class A {
  19.     public:
  20.         void f(int);
  21.         static void f(char);
  22.     };
  23.  
  24.     class B : public A {
  25.     };
  26.  
  27.     void foo(B& b,char c) {
  28.         b.f(c);
  29.     }
  30.  
  31. Here, the candidates functions for overloading resolution are
  32. f(const A&,int) and f(?,char) where '?' matches any type,
  33. and the call arguments have types B& and char.
  34. The first candidate needs a conversion from B& to const A& for the
  35. first argument while the second is an exact match. The second
  36. candidate has an exact match for the first argument while the
  37. second requires a char->int promotion. Therefore, the call
  38. is ambiguous.
  39.  
  40. Is the above correct, or did I miss something ?
  41. If I understood correctly, is this the intended behaviour ? 
  42. If so, why ? 
  43. I think selecting f(char) would make more sense here (and that's
  44. what the compilers I have tested do).
  45.  
  46. ___________________________________________________
  47.  
  48. Emmanuel Lesueur  -   elesueur@ens-lyon.fr
  49. ---
  50. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  51. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  52. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  53. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  54. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  55.